Skip to content

Conversation

@rozza
Copy link
Member

@rozza rozza commented Oct 9, 2025

Moved specifications submodule out of driver-core into a testing directory.
Deleted old copy of bson specification tests and updated to use the submodule
Fixed Json output for positive exponents to match the the extended json specification

Added test exceptions to BinaryVectorGenericBsonTest
Added BsonBinaryVector prose tests
Added extra regression tests to ensure both explicit and implicit doubles with positive exponets parse as expected.

JAVA-5877
JAVA-5779
JAVA-5782
JAVA-5652

@rozza rozza requested a review from vbabanin October 9, 2025 10:51
@rozza rozza requested a review from a team as a code owner October 9, 2025 10:51
@rozza rozza requested a review from Copilot October 9, 2025 10:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR reorganizes specification testing by moving the MongoDB specifications submodule from driver-core to a shared testing directory, updates JSON output for positive exponents to match the extended JSON specification, and adds comprehensive testing for BsonBinaryVector functionality.

  • Moved specifications submodule from driver-core to shared testing directory for better organization
  • Fixed JSON output to include explicit "+" signs for positive exponents in extended JSON
  • Added comprehensive testing for BsonBinaryVector including prose tests and enhanced validation

Reviewed Changes

Copilot reviewed 47 out of 49 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
.gitmodules Updated submodule path from driver-core to testing directory
bson/build.gradle.kts Added test resource processing to include shared testing resources
driver-core/build.gradle.kts Added test resource processing to include shared testing resources
bson/src/main/org/bson/json/*.java Modified double converters to use consistent JSON formatting with explicit positive exponents
bson/src/main/org/bson/BinaryVector.java Added validation logging for non-zero padding bits
bson/src/test/unit/org/bson/vector/BinaryVectorGenericBsonTest.java Enhanced test coverage and updated to use new spec test location
bson/src/test/unit/org/bson/*.java Updated test references to use new specification test helper method
bson/src/test/resources/bson*/ Removed old BSON specification test files (now using submodule)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Moved specifications submodule out of driver-core into a testing directory.
Deleted old copy of bson specification tests and updated to use the submodule
Fixed Json output for positive exponents to match the the extended json specification

Added test exceptions to BinaryVectorGenericBsonTest
Added BsonBinaryVector prose tests
Added extra regression tests to ensure both explicit and implicit doubles with positive exponets parse as expected.

JAVA-5877
JAVA-5779
JAVA-5782
JAVA-5652

@DisplayName("Treatment of non-zero ignored bits: 2. Decoding")
@Test
void decodingWithNonZeroIgnoredBits() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BinaryVectorTest only covers use-cases for creating BinaryVectors from constructor methods of BinaryVector API.

We have a separate class BsonBinaryTest for decoding tests with methods:
shouldDecodeInt8Vector, shouldEncodePackedBitVector. I suggest we move decoding test method there to keep them coherent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed this file to BinaryVectorProseTest as these include the new tests in the spec.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note there are corpus tests also that cover the BsonBinary api, these prose and extra tests allow for extra testing of the API.

}

// TODO JAVA-5848 in 6.0.0 "Padding specified with no vector data PACKED_BIT" will throw an error (currently logs a warning).
if (testCase.containsKey("canonical_bson") && !testDescription.equals("Padding specified with no vector data PACKED_BIT")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already maintain a list of ignored tests in TEST_NAMES_TO_IGNORE. Should we move this check to TEST_NAMES_TO_IGNORE to keep it consistent and easier to track?

This would also simplify the method signature by removing the testDescription parameter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

BsonArray arrayVector = testCase.getArray("vector");
byte expectedPadding = (byte) testCase.getInt32("padding").getValue();
byte dtypeByte = Byte.decode(testCase.getString("dtype_hex").getValue());
Copy link
Member

@vbabanin vbabanin Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an error occurs in the test setup (for example, Byte.decode("") throwing an IllegalArgumentException, an intentional mistake in this case), all tests currently pass.

This happens because IllegalArgumentException and IllegalStateException are caught broadly in assertValidationException covering both the setup logic and the SUT, and treated as expected results.

While I see the benefit of a more generalized approach, I think we should assert exceptions only where they’re explicitly expected, as we did previously and still do in runValidTestCase.

That would separate test setup of code under test and reduce the risk of unintentionally masking setup errors as successful test results.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

BinaryVector.packedBitVector(bytes, expectedPadding);
break;
case FLOAT32:
throw new IllegalArgumentException("Float32 is not supported");
Copy link
Member

@vbabanin vbabanin Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, when a JSON test that we don’t support runs through the runner, it throws IllegalArgumentException, which propagates to assertValidationException and is treated as a successful execution.

Since we have a few such unsupported cases (9 in total, with only 4 currently reported as skipped via TEST_NAMES_TO_IGNORE), it could be clearer to surface them as skipped instead.

We could do that by throwing a TestAbortedException, for example: Assumptions.abort(dataType + " is not supported with padding");, so these cases are reported as skipped without implying they passed successfully.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

tasks.processTestResources {
from("${rootProject.projectDir}/testing/resources")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I think, In the future, we could also consider creating a separate module for testing utilities, so shared helpers can be reused across sync, reactive, core, and BSON modules.

@rozza
Copy link
Member Author

rozza commented Oct 21, 2025

@vbabanin I've updated the names of the tests to be more inline with the spec location and to identify the prose tests.

I also moved the validation to the constructors as it seemed the best place to have it.

Copy link
Member Author

@rozza rozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code

}

// TODO JAVA-5848 in 6.0.0 "Padding specified with no vector data PACKED_BIT" will throw an error (currently logs a warning).
if (testCase.containsKey("canonical_bson") && !testDescription.equals("Padding specified with no vector data PACKED_BIT")) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


@DisplayName("Treatment of non-zero ignored bits: 2. Decoding")
@Test
void decodingWithNonZeroIgnoredBits() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed this file to BinaryVectorProseTest as these include the new tests in the spec.

BsonArray arrayVector = testCase.getArray("vector");
byte expectedPadding = (byte) testCase.getInt32("padding").getValue();
byte dtypeByte = Byte.decode(testCase.getString("dtype_hex").getValue());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

BinaryVector.packedBitVector(bytes, expectedPadding);
break;
case FLOAT32:
throw new IllegalArgumentException("Float32 is not supported");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@rozza rozza requested a review from vbabanin October 21, 2025 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants